package com.atguigu.dao.impl;

import com.atguigu.dao.BaseDao;
import com.atguigu.dao.OrderDao;
import com.atguigu.domain.Cart;
import com.atguigu.domain.Order;
import com.atguigu.domain.User;

import java.util.List;

/**
 * @author dl
 * @date 2020/5/4 13:38
 */
public class OrderDaoImpl extends BaseDao<Order> implements OrderDao {

    @Override
    public int save(Order order) {
        String sql = "insert into bs_order(order_id,create_time,total_money,status,user_id) values(?,?,?,?,?)";
        return update(sql,order.getOrderId(),order.getCreateTime(),
                order.getTotalMoney(),order.getStatus(),order.getUserId());
    }

    @Override
    public int update(Order order) {
        String sql = "update bs_order set status = ? where order_id = ?";
        return update(sql,order.getStatus(),order.getOrderId());
    }

    @Override
    public List<Order> listOrders() {
        String sql = "select order_id orderId, create_time createTime, total_money totalMoney, status, user_id userId from bs_order";
        return getBeanList(sql);
    }


    @Override
    public List<Order> getOrderByUserId(String userId) {
        String sql = "select order_id orderId, create_time createTime, total_money totalMoney, status, user_id userId from bs_order where user_id = ?";
        return getBeanList(sql,userId);
    }
}
